package cfca.seal.common;

import java.util.List;

public class Page<T>
{
  private int pageSize = 10;
  private int pageNo = 1;

  private int totalPage = 1;
  private long totalCount;
  private long start;
  private long end;
  private int firstPageNo = 1;
  private int previousPageNo;
  private int nextPageNo;
  private int lastPageNo;
  private boolean firstPage;
  private boolean lastPage;
  private List<T> beans;
  private T pageTotalBean;
  private T totalBean;
  private String formId = "";
  private String infoDiv;
  private String uri = "v_list.do";

  public Page(int totalCount, int pageSize, int pageNo) {
    this.totalCount = totalCount;
    this.pageSize = pageSize;
    this.pageNo = pageNo;

    this.firstPage = false;
    this.lastPage = false;
    init();
  }

  public Page(int totalCount, int pageSize, int pageNo, String uri) {
    this.totalCount = totalCount;
    this.pageSize = pageSize;
    this.pageNo = pageNo;

    this.firstPage = false;
    this.lastPage = false;

    this.uri = uri;
    init();
  }

  public Page(int totalCount) {
    this.totalCount = totalCount;
    init();
  }

  public void init() {
    if (this.totalCount < 0L) {
      this.totalCount = 0L;
    }
    if (this.pageSize < 0) {
      this.pageSize = 0;
    }

    if (this.totalCount % this.pageSize == 0L) {
      this.totalPage = ((int)(this.totalCount / this.pageSize));
      this.totalPage = (this.totalPage <= 0 ? 1 : this.totalPage);
    } else {
      this.totalPage = ((int)(this.totalCount / this.pageSize + 1L));
    }
    if (this.pageNo <= 1) {
      this.pageNo = 1;
      this.firstPage = true;
    }

    if ((this.pageNo >= this.totalPage) && (this.totalCount >= 0L)) {
      this.pageNo = this.totalPage;
      this.lastPage = true;
    }

    if (this.pageNo == 1)
      this.previousPageNo = 1;
    else {
      this.previousPageNo = (this.pageNo - 1);
    }

    if (this.pageNo == this.totalPage)
      this.nextPageNo = this.totalPage;
    else {
      this.nextPageNo = (this.pageNo + 1);
    }

    this.start = ((this.pageNo - 1) * this.pageSize + 1);
    this.end = (this.start + this.pageSize - 1L > this.totalCount ? this.totalCount : this.start + this.pageSize - 1L);

    this.lastPageNo = this.totalPage;
  }

  public int getFirstPageNo() {
    return this.firstPageNo;
  }

  public int getPreviousPageNo() {
    return this.previousPageNo;
  }

  public int getNextPageNo() {
    return this.nextPageNo;
  }

  public int getLastPageNo() {
    return this.lastPageNo;
  }

  public int getTotalPage() {
    return this.totalPage;
  }

  public long getTotalCount() {
    return this.totalCount;
  }

  public int getPageNo() {
    return this.pageNo;
  }

  public List<T> getBeans() {
    return this.beans;
  }

  public void setBeans(List<T> beans) {
    this.beans = beans;
  }

  public String getInfoDiv() {
    return this.infoDiv;
  }

  public void setInfoDiv(String infoDiv) {
    this.infoDiv = infoDiv;
  }

  public T getPageTotalBean() {
    return this.pageTotalBean;
  }

  public void setPageTotalBean(T pageTotalBean) {
    this.pageTotalBean = pageTotalBean;
  }

  public T getTotalBean() {
    return this.totalBean;
  }

  public void setTotalBean(T totalBean) {
    this.totalBean = totalBean;
  }

  public long getStart() {
    return this.start;
  }

  public long getEnd() {
    return this.end;
  }

  public boolean isFirstPage() {
    return this.firstPage;
  }

  public void setFirstPage(boolean firstPage) {
    this.firstPage = firstPage;
  }

  public boolean isLastPage() {
    return this.lastPage;
  }

  public void setLastPage(boolean lastPage) {
    this.lastPage = lastPage;
  }

  public String getUri() {
    return this.uri;
  }

  public void setUri(String uri) {
    this.uri = uri;
  }

  public String getFormId() {
    return this.formId;
  }

  public void setFormId(String formId) {
    this.formId = formId;
  }
}